package init

import (
	"fmt"
	"log"
	"order_srv/basic/config"

	"github.com/go-redis/redis/v8"
)

func InitRedis() {
	cfg := config.AppCong.Redis
	addr := fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)
	config.Rdb = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: cfg.Password, // no password set
		DB:       15,           // use default DB
	})

	err := config.Rdb.Set(config.Ctx, "key", "value", 0).Err()
	if err != nil {
		panic(err)
	}
	log.Println("redis inits success")
}
